import { createStore } from 'vuex'
import {clearUserToken, getToken, getUserName, setUserToken} from "../../plugins/cookie";

export default createStore({
  state: {
      username:getUserName(),
      token:getToken()
  },
  getters: {
  },
  mutations: {
      login:function (state, {username, token}){
          // 在state中设置username，token
          state.username = username;
          state.token = token;
          // 在cookie中设置
          setUserToken(username,token);
      },
      logout:function (state) {
          state.username = '';
          state.token = '';
          clearUserToken();
      }
  },
  actions: {
  },
  modules: {
  }
})
